<?php
class Log {
	const DATE_FORMAT	= "Y.m.d H:i:s";
	const INFO_FORMAT	= "[INFO %s] %s";
	const ERROR_FORMAT	= "[ERROR* %s] %s";
	
	public static function info($message)
	{
		if (!defined("ML_LOG_INFO") or ML_LOG_INFO === FALSE) return;
		$time = date(self::DATE_FORMAT);
		self::put(sprintf(self::INFO_FORMAT, $time, $message).PHP_EOL);
	}
	
	public static function error($message)
	{
		if (!defined("ML_LOG_ERROR") or ML_LOG_ERROR === FALSE) return;
		$time = date(self::DATE_FORMAT);
		self::put(sprintf(self::ERROR_FORMAT, $time, $message).PHP_EOL);
	}
	
	private static function put($line)
	{
		$log_file = fopen(ML_LOG."/".ML_LOG_FILE_NAME, "a");
		if ($log_file !== FALSE) {
			fwrite($log_file, $line);
			fclose($log_file);
		}
	}
}